

#import "BCNSpcWERule1.h"

@implementation BCNSpcWERule1

-(void) initWithSide: (BCNSpcControlSide) side Limit:(BCNSpcControlLimit*) limit
{
	pointCount =1;
	controlSide = side;
	
	[limit retain];
	[controlLimit release];
	controlLimit = limit;
}

-(BCNSpcRuleType) RuleType
{
	return BCNSpcRuleType.WERule1;
}

-(NSString) GetDescription
{
		return @"Any single data point falls outside the 3σ limit from the centerline.";
}

-(int) GetRulePointCount
{
	return PointCount;
}

-(BOOL)AddPoint:(double) data
{
	if (data == MAXFLOAT)
	    return NO;
	    
	switch(controlSide)
	{
	    case BCNSpcControlSide.Lower:
	        if(data< controlLimit.LCL)
	            return YES;
	        break;
	    case BCNSpcControlSide.Upper:
	        if( data < controlLimit.UCL)
	            return YES;
	        break;
	    case BCNSpcControlSide.Both:
	        if(data< controlLimit.LCL || data> controlLimit.UCL)
	            return YES;
	        break;
	}
	return NO;
}

-(BOOL)AddPoint:(double) data size:(double) sampleSize
{
	if (sampleSize < 0) 
	    return NO;
	
	// calculate new limit for given new sample size.
	[controlLimit Calculate: (int)sampleSize];
	return [self AddPoint: data];
}

-(void)Reset
{
}

-(void) dealloc
{
  [controlLimit release];
  [super dealloc];
}

@end //	BCNSpcWERule1